package com.itheima.excel;

import com.alibaba.excel.EasyExcel;
import com.itheima.excel.entity.User;
import com.itheima.excel.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collection;

@SpringBootTest
public class SimpleWrite {

    String fileName = "simpleWrite.xlsx";

    /**
     * EasyExcel.write()写Excel
     */
    @Test
    public void simpleWrite2() {
        //fileName: 写出的文件名
        //User.class: 和Excel对于的对象类型
        //测试数据：工作簿名称
        //data(): 调用方法获取需要写出的数据
        EasyExcel.write(fileName,User.class).sheet("测试数据").doWrite(data());
    }

    @Autowired
    UserMapper userMapper;

    /**
     * 查询数据 写出到Excel
     */
    private Collection<?> data() {
        return userMapper.list();
    }
}
